package cn.wlh.learn.webmagic.processor;

import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.model.ConsolePageModelPipeline;
import us.codecraft.webmagic.model.HasKey;
import us.codecraft.webmagic.model.OOSpider;
import us.codecraft.webmagic.model.annotation.ExtractBy;
import us.codecraft.webmagic.model.annotation.HelpUrl;
import us.codecraft.webmagic.model.annotation.TargetUrl;

/**
 * https://www.dazhongbaojian0.com/item-list-catid-5.html
 *
 *
 * https://www.dazhongbaojian0.com/item-list-branch_id-0-catid-5-aid-0-num-20-total-330-page-1.html
 * https://www.dazhongbaojian0.com/item-list-branch_id-0-catid-5-aid-0-num-20-total-330-page-2.html
 *
 * https://www.dazhongbaojian0.com/item-1647.html
 * @author code4crafter@gmail.com <br>
 * @since 0.3.2
 */
//@TargetUrl("https://github.com/\\w+/\\w+")
@TargetUrl("https://www.dazhongbaojian0.com/item-\\w+\\.html")
//@HelpUrl({"https://github.com/\\w+\\?tab=repositories", "https://github.com/\\w+", "https://github.com/explore/*"})
@HelpUrl({"https://www.dazhongbaojian0.com/item-list-branch_id-0-catid-5-aid-0-num-20-total-330-page-\\w+\\.html"})
public class DaZhongBJRepo implements HasKey {
    //*[@id="item_left"]/div[1]/div/div[1]/h2
    @ExtractBy(value = "//*[@id=\"item_left\"]/div[1]/div/div[1]/h2", notNull = true)
    private String name;


//    @ExtractByUrl("https://github\\.com/(\\w+)/.*")
//    private String author;
//
//    @ExtractBy("//div[@id='readme']/tidyText()")
//    private String readme;
//
//    @ExtractBy(value = "//div[@class='repository-lang-stats']//li//span[@class='lang']/text()", multi = true)
//    private List<String> language;
//
//    @ExtractBy("//ul[@class='pagehead-actions']/li[1]//a[@class='social-count js-social-count']/text()")
//    private int star;
//
//    @ExtractBy("//ul[@class='pagehead-actions']/li[2]//a[@class='social-count']/text()")
//    private int fork;
//
//    @ExtractByUrl
//    private String url;

    public static void main(String[] args) {
        OOSpider.create(Site.me().setSleepTime(100)
                , new ConsolePageModelPipeline(), DaZhongBJRepo.class)
                .addUrl("https://www.dazhongbaojian0.com/item-list-branch_id-0-catid-5-aid-0-num-20-total-330-page-1.html").thread(10).run();
    }

    @Override
    public String key() {
        return  name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
